package main

import "fmt"

/*
	嵌套匿名结构体
*/

type User struct {
	UserName string
	Password string
	Address
	Email
}

type Address struct {
	Name    string
	Phone   string
	City    string
	AddTime string
}

type Email struct {
	Account string
	AddTime string
}

func main() {
	var u User
	u.UserName = "张三"
	u.Password = "456789"
	u.Address.Name = "张先生"
	u.Address.Phone = "15323132132"
	u.Address.City = "深圳市福田区"

	u.City = "上海" //当访问结构体成员时会先在结构体中查找该字段，找不到再去匿名结构体中查找

	//u.AddTime = "2025-11-19"	//./main.go:38:3: ambiguous selector u.AddTime
	u.Address.AddTime = "2025-06-01"
	u.Email.AddTime = "2025-05-01"
	fmt.Printf("%#v\n", u) //main.User{UserName:"张三", Password:"456789", Address:main.Address{Name:"张先生", Phone:"15323132132", City:"上海", AddTime:"2025-06-01"}, Email:main.Email{Account:"", AddTime:"2025-05-01"}}

}
